<template>
	<view class="content">
		<view class="tabT">
			<view class="items" v-for="(item,i) in meau" :key="i" @click="tabChange(i)">
				<view class="title" :class="pagination.status*1==i?'active':''">
					{{item.title}}
				</view>
			</view>
		</view>
		<view class="tabD">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption">
				<view class="items" v-for="(item,i) in list" :key="i">
					<view class="t">
						<view class="l">
							<image :src="item.bank_logo" mode="aspectFill"></image> {{item.bank_name}}
						</view>

						<view class="r" @click="goLink(item.id)">
							查看详情 <u-icon size="24" color="#ec6a38" name="arrow-right"></u-icon>
						</view>

					</view>
					<view class="ul">
						<view class="li">
							<view class="l">
								还款开始日期
							</view>
							<view class="r">
								{{item.date_list[0]}}
							</view>
						</view>
						<view class="li">
							<view class="l">
								预留额度
							</view>
							<view class="r">
								{{item.reserve_amount}}
							</view>
						</view>
						<view class="li">
							<view class="l">
								已消费
							</view>
							<view class="r">
								{{item.already_consume_amount}}
							</view>
						</view>
						<view class="li">
							<view class="l">
								已还款
							</view>
							<view class="r">
								{{item.already_repayment_amount}}
							</view>
						</view>
						<view class="li">
							<view class="l">
								已扣手续费
							</view>
							<view class="r">
								{{item.already_produce_charge}}
							</view>
						</view>
					</view>
					<view class="allTotal">
						还款总额：<text>¥{{item.amount}}</text>
					</view>
					<view class="type">

						<template v-if="item.status==1">
							<text class="ac2">状态：已制定 </text>
						</template>
						<template v-if="item.status==2">
							<text class="ac2">状态：进行中 </text>
						</template>
						<template v-if="item.status==3">
							<text>状态：已完成 </text>
						</template>
						<template v-if="item.status==4">
							<text class="ac1">状态：已取消 </text>
						</template>
						<template v-if="item.status==5">
							<text class="ac1">状态：已失败 </text>
						</template>
						<view class="cancelPlan" v-if="item.status==2 || item.status==1" @click="planCancel(item.id,i)">
							取消
						</view>
					</view>

				</view>
			</mescroll-body>
		</view>
	</view>
</template>
<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {planList, planCancel} from '@/common/creditcardmachine.api.js'
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				doneType: 0,
				meau: [{
						title: '全部',
						type: 0
					},
					{
						title: '已制定',
						type: 1
					},
					{
						title: '进行中',
						type: 2
					},
					{
						title: '已完成',
						type: 3
					},
					{
						title: '已取消',
						type: 4
					},
					{
						title: '已失败',
						type: 5
					},
				],
				downOption:{},
				upOption:{},
				pagination: {
					current: 1,
					page: 1,
					pageSize: 0,
					total: 0,
					status: 0

				},
				list: []
			}
		},
		// 
		onLoad() {

		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			console.log('下拉加载')
		},
		created() {

		},
		methods: {
			getList() {
				let that = this;
				let params = {}
				params.page = that.pagination.current;
				params.type = that.pagination.type;
				if (that.pagination.status != 0) {
					params.status = that.pagination.status;
				}
				params.page_size = 20
				planList(params).then(res => {
					that.mescroll.endByPage(res.list.length, res.pagination.total)
					if (!res.list) {
						res.list = []
					}
					if (!res.pagination) {
						res.pagination = {}
						res.pagination.total = 0
					}

					that.pagination.page = that.pagination.current
					if (that.pagination.current * 1 == 1) {
						that.list = res.list
					} else {
						that.list = [...that.list, ...res.list]
					}
					res.pagination.status = that.pagination.status
					that.pagination = res.pagination;
					that.pagination.current = that.pagination.current * 1 + 1
					that.pagination.page = that.pagination.current * 1 + 1
				})
			},
			tabChange(e) {
				this.pagination.page = 1;
				this.pagination.current = 1;
				this.pagination.status = e
				this.list = []
				this.mescroll.scrollTo(0)
				this.mescroll.setPageNum(1)
				this.mescroll.resetUpScroll();
			},
			upCallback() {
				this.getList()
			},
			downCallback() {
				this.pagination.page = 1;
				this.pagination.current = 1;
				this.mescroll.resetUpScroll();
			},
			showCalendar() {
				this.showCalendarStatus = true
			},
			openPage(path, params = {}) {
				this.$u.route({
					url: path,
					params
				})
			},
			goLink(item) {
				console.log(item)
				let params = {
					deCode: {}
				};
				params.deCode = JSON.stringify(item)
				this.openPage('/pages/creditcard/autoPayMoney/info', params)

			},
			// 取消计划
			planCancel(id,index){
				let that = this
				uni.showToast({
					title:'正在取消计划...'
				})
				planCancel({plan_id:id}).then(res => {
					uni.hideLoading()
					that.list[index].status = 4;
					uni.showToast({
						title:'取消成功～'
					})
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #f4f5f7;
	}
</style>
<style scoped lang="scss">
	.tabT {
		display: flex;
		background-color: #ec6a38;
		height: 80rpx;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		box-shadow: 0 0 10rpx 10rpx #f4f5f7;
		z-index: 9;

		.items {
			width: 16.6%;
			text-align: center;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;

			.title {
				font-size: 28rpx;
				position: relative;
				height: 100%;
				line-height: 80rpx;
				color: #f7d8cd;

				&::after {
					position: absolute;
					left: 0;
					bottom: 0;
					height: 3px;
					background-color: transparent;
					content: '';
					display: block;
					width: 100%;
				}
			}

			.title.active {
				color: #fff;

				&::after {
					background-color: #fff;
				}
			}
		}
	}

	.tabD {
		padding: 0 30rpx;
		margin-top: 80rpx;

		.items {
			padding: 20rpx 20rpx;

			background-color: #fff;
			border-radius: 16rpx;
			margin: 25rpx 0;
		}

		.t {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 96rpx;
			border-bottom: 1px solid #eee;
			font-size: 28rpx;

			.l {
				display: flex;
				align-items: center;

				image {
					width: 55rpx;
					height: 55rpx;
					display: block;
					margin-right: 10rpx;
					border-radius: 100%;
				}
			}

			.r {
				display: flex;
				flex-direction: row;
				font-size: 26rpx;
				color: #ec6a38;
				align-items: baseline;
				justify-content: center;
			}
		}

		.ul {
			padding: 15rpx 0;
		}

		.li {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 26rpx;
			line-height: 2;

			.l {
				color: #b3b3b3;
			}

			.r {
				color: #262626;
				font-weight: bold;
			}
		}

		.allTotal {
			text-align: right;
			line-height: 2;
			color: #b3b3b3;
			font-size: 26rpx;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #eee;

			text {
				color: #f24e3a;
				font-weight: bold;
			}
		}


		.type {
			height: 73rpx;
			line-height: 73rpx;
			font-size: 26rpx;
			color: #488aeb;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.cancelPlan {
				height: 50rpx;
				line-height: 50rpx;
				background-color: #ec6a38;
				color: #fff;
				padding: 0 30rpx;
				border-radius: 8rpx;

			}

			.ac1 {
				color: red;
			}

			.ac2 {
				color: #ec6a38;
			}
		}


	}
</style>
